/*
 *  game_ui.h
 *  BioBreak
 *
 *  Created by terry franguiadakis on 2/22/09.
 *  Copyright 2009 __MyCompanyName__. All rights reserved.
 *
 */
#pragma once

#include "bbmath.h"
#include "go.h"
#include "render.h"
#include "gomgr.h"
#include "camera.h"

// -----------------------------------------------------------------------------
// Forward Declarations
class CTextureCounter;

// -----------------------------------------------------------------------------

class BBUIElement 
{
public:
							BBUIElement();
							
	bool					IsVisible() const {
								return m_isVisible; }
	void					SetIsVisible(bool i_is) {
								m_isVisible = i_is; }
    virtual bool			IsPointContained(const Vector2f& i_pos) {
								return false; }
    virtual void			Render() = 0;
	virtual void			Update() = 0;
    virtual bool			HasAction() {
								return false; }
    virtual void			Remove()  {}
	virtual void			SetTextureUI(const CTexture* i_texture) {
								m_textureUI = i_texture; }
	virtual const CTexture*	GetTextureUI() {
								return m_textureUI; }
	
private:

	const CTexture*	m_textureUI;
	bool			m_isVisible;
};

// -----------------------------------------------------------------------------

class CUITimer
{
public:
			CUITimer(const Vector2f& i_pos);
	void	Render();
	void	Update();
	bool	IsVisible() const {
				return m_isVisible; }
	void	SetTimer(float i_timeLeft);
	void	StartTimer();			// makes visible and starts counting down
	void	PauseTimer();			// makes visible and pauses time at the current count
	void	StopTimer();			// hides timer and pauses at current count
	bool	IsComplete() const {	// if the timer is sitting completed
				return m_state == EState_Complete; } 
	bool	IsPaused() const {
				return m_state == EState_Paused; }
	bool	IsRunning() const {
				return m_state == EState_Running; }
	bool	IsActive() const {
				return m_state != EState_InActive; }
private:

	enum EState
	{
		EState_InActive,
		EState_Running,
		EState_Paused,
		EState_Complete,
	};
	
	void	setState(EState i_state);

	EState					m_state;				// the state of the current timer
	float					m_timeLeft;				// amount of time left in seconds
	bool					m_isVisible;			// is the timer visible?
	Transform2D				m_transform;			// positional information
	static CTextureCounter*	s_timerCounter;			// static texture for elements to render out the time
};

// -----------------------------------------------------------------------------

class CProgressBar
{
public:
							CProgressBar();
	
	void					Render();
	void					SetProgress(float i_progress);
	void					SetScale(float i_size) {
								m_transform.SetScale(i_size); }
	void					SetPos(const Vector2f& i_pos) {
								m_transform.SetPos(i_pos); }
	
	void					SetWidth(float i_width);
	void					SetHeight(float i_height);
	void					SetBackgroundColor(const Color4f& i_color) {
								m_bgColor = i_color; }
	void					SetProgressColor(const Color4f& i_color) {
								m_progressColor = i_color; }
	
	bool					IsVisible() const {
								return m_isVisible; }
	void					SetIsVisible(bool i_is) {
								m_isVisible = i_is; }
								
private:

	float			m_width;
	float			m_height;
	Color4f			m_progressColor;
	Color4f			m_bgColor;
	float			m_progress;
	bool			m_isVisible;
    Transform2D		m_transform;
};


// -----------------------------------------------------------------------------
 
class BBBackElement: public BBUIElement
{
public:
    void			SetDepth(float i_depth) {
						m_transform.SetDepth(i_depth); }
   
	// BBUIElement overrides
    virtual bool	IsPointContained(const Vector2f& i_pos);
    virtual void	Render();
	virtual void	Update() {}
    
private:
    Transform2D m_transform;
};


// -----------------------------------------------------------------------------

class BBUIButton : public BBUIElement
{
public:

	enum EButtonFunction
	{
		EButtonFunction_GoCreator,
		EButtonFunction_Pause,
		EButtonFunction_Play
	};
	
	enum EState
	{
		BEGIN_ENUM(EState_),
		EState_Usable,
		EState_InUse,
		EState_Disabled,
		END_ENUM(EState_)
	};
    
					BBUIButton(const Vector2f& i_pos, float i_size, EClass i_spawnClass, EButtonFunction i_buttonContext = EButtonFunction_GoCreator);
    virtual bool	IsPointContained(const Vector2f& i_pos);
    virtual bool	HasAction() {
						return true; }
    virtual void	Apply(const Vector2f& i_pos);
    virtual void	Remove();
    virtual bool	IsPlaced();
	virtual void	ClearPlaced();
    virtual void	Render();
	virtual void	Update();
	
private:
    
    Vector2f		convertPosToWorldSpace(const Vector2f& i_pos);
    void            renderPrice();
	void			setState(EState i_state);
	
	const CTexture*	m_textureUIUsed;	//texture of button when in use.
    EClass			m_spawnClass;		//if this class spawn an object.. what class?
    Transform2D		m_transform;		//position of the button
	EButtonFunction	m_buttonContext;
    EState			m_state;			//state of the button
	
    static CTextureCounter* s_price;	//static texture for elements to render out their price
};

/*-----------------------------------EOF!-----------------------------------*/

